const { commentAPI } = require('../../../utils/api');

Page({
  data: {
    orderId: '',
    rating: 5,
    content: ''
  },
  onLoad(options) {
    this.setData({ orderId: options.id });
  },
  onRatingChange(e) {
    this.setData({ rating: e.detail.value });
  },
  onContentInput(e) {
    this.setData({ content: e.detail.value });
  },
  onSubmit() {
    if (!this.data.content) {
      wx.showToast({ title: '请填写评价内容', icon: 'none' });
      return;
    }
    commentAPI.add(
      this.data.orderId,
      this.data.content,
      this.data.rating
    ).then(() => {
      wx.showToast({ title: '评价成功', icon: 'success' });
      setTimeout(() => {
        wx.navigateBack();
      }, 800);
    });
  }
}); 